package org.zcl.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @PROJECT_NAME:
 * @DESCRIPTION:
 * @USER: ZhuChengLin
 * @DATE: 2021/11/23 16:26
 */
public class MapSortDemo {
    public static void main(String[] args) {

        HashMap<String, String> map = new HashMap<>();
        map.put("3", "33");
        map.put("1", "11");
        map.put("2", "22");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println("排序之前:" + entry.getKey() + " 值" + entry.getValue());

        }
        System.out.println("======================================================");
        SortedMap<String, String> sort = new TreeMap<>(map);
        Set<Map.Entry<String, String>> entry1 = sort.entrySet();
        Iterator<Map.Entry<String, String>> it = entry1.iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> entry = it.next();
            System.out.println("排序之后:" + entry.getKey() + " 值" + entry.getValue());
        }
        System.out.println("======================================================");
        Map<Object, Object> map1 = new HashMap<>();
        map.put(null, null);
        System.out.println(map1);
        System.out.println("======================================================");

        Map<Object, Object> map2 = new TreeMap<>();
        map2.put(0, null);
        System.out.println(map2);

        int n = 1000 - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        System.out.println(n + 1);

    }
}
